# Ignore this file if you are not trying to translating this mod.
# Also ignore if you are translating this mod for the first time after April 2024.
# Starting from mod version 1.2.0, the keys of the mod's language files have changed for a unified format ("NBO.{NameOfNeedClass}.{NameOfNeedSetting}") for future mod compatibilies.
# There's a temporary compatibility patch built into the mod for old language files, but it theoretically slows the mod down a little so I want to remove it soon.
# That means if you have been translating the mod before version 1.2.0 (April 2024), the old text might stop working soon.
# To fix it, you can either manually replace the keys in your translation file to align with the updated English/Chinese files,
#   or run this file as a Python script to automatically replace the language files in this directory:
# 1. Back up your translation file, then copy it to the same directory as this one
# 2. Rename this file's end from ".txt" to ".py"
# 3. Right click this file and run with python.exe
# Thank you for help translating my mod!

# 如果你并不打算翻译这个模组，你可以忽略这个文件。
# 如果你在2024年4月后第一次尝试翻译这个模组，你也可以忽略这个文件。
# 从模组版本1.2.0开始，模组的部分语言key被替换了，目的是为了未来的模组兼容性统一key格式为"NBO.{需求类名称}.{需求溢出设置名称}"。
# 目前模组里面自带临时兼容补丁，但该补丁理论上会拖慢模组一点点，所以我想尽快把它删掉。
# 也就是说，如果你在模组1.2.0版本(2024年4月)前翻译过这个模组，旧版的翻译可能很快会失效。
# 为了修复它，你可以选择手动把旧的语言key替换成新的，也可以选择将这个文件作为Python脚本运行来自动替换同一位置下的所有语言文件:
# 1. 先备份好你的翻译文件，把它复制到同路径下
# 2. 把这个文件后缀改成.py
# 3. 右键使用python.exe运行
# 感谢你翻译我的模组！

replacement_keys = [
  ['NBO.RestartReq_tip', 'NBO.RestartReq_Tip'],
  ['NBO.RestartNReq_tip', 'NBO.RestartNReq_Tip'],
  ['NBO.FoodOverfEnabled', 'NBO.Need_Food.OverfEnabled'],
  ['NBO.FoodOverfEnabled_Tip', 'NBO.Need_Food.OverfEnabled_Tip'],
  ['NBO.FoodOverfPerc', 'NBO.Need_Food.OverfPerc'],
  ['NBO.FoodOverfPerc_Tip', 'NBO.Need_Food.OverfPerc_Tip'],
  ['NBO.FoodOverfVal', 'NBO.Need_Food.OverflowBonus'],
  ['NBO.FoodOverfVal_Tip', 'NBO.Need_Food.OverflowBonus_Tip'],
  ['NBO.FoodOverfDisableEating', 'NBO.Need_Food.DisableEating'],
  ['NBO.FoodOverfDisableEating_Tip', 'NBO.Need_Food.DisableEating_Tip'],
  ['NBO.NoFoodOverfRace', 'NBO.NoOverf.Race'],
  ['NBO.NoFoodOverfRace_Tip', 'NBO.NoOverf.Race_Tip'],
  ['NBO.NoFoodOverfHediff', 'NBO.NoOverf.Hediff'],
  ['NBO.NoFoodOverfHediff_Tip', 'NBO.NoOverf.Hediff_Tip'],
  ['NBO.FoodOverfAffectHunger', 'NBO.Need_Food.HealthEnable.HungerFactor'],
  ['NBO.FoodOverfAffectHunger_Tip', 'NBO.Need_Food.HealthEnable.HungerFactor_Tip'],
  ['NBO.FoodOverfAffectHealing', 'NBO.Need_Food.HealthEnable.HealingFactor'],
  ['NBO.FoodOverfAffectHealing_Tip', 'NBO.Need_Food.HealthEnable.HealingFactor_Tip'],
  ['NBO.FoodOverfAffectMoving', 'NBO.Need_Food.HealthEnable.MovingOffset'],
  ['NBO.FoodOverfAffectMoving_Tip', 'NBO.Need_Food.HealthEnable.MovingOffset_Tip'],
  ['NBO.FoodOverfCauseVomit', 'NBO.Need_Food.HealthEnable.VomitFreq'],
  ['NBO.FoodOverfCauseVomit_Tip', 'NBO.Need_Food.HealthEnable.VomitFreq_Tip'],
  ['NBO.FoodOverfAffectEating', 'NBO.Need_Food.HealthEnable.EatingOffset'],
  ['NBO.FoodOverfAffectEating_Tip', 'NBO.Need_Food.HealthEnable.EatingOffset_Tip'],
  ['NBO.FoodOverfHealthDetails', 'NBO.Need_Food.HealthDetails'],
  ['NBO.FoodOverfHealthDetails_Tip', 'NBO.Need_Food.HealthDetails_Tip'],
  ['NBO.FoodOverfNonHumanMult', 'NBO.Need_Food.NonHumanMult'],
  ['NBO.FoodOverfNonHumanMult_Tip', 'NBO.Need_Food.NonHumanMult_Tip'],
  ['NBO.FoodOverfGourmandMult', 'NBO.Need_Food.GourmandMult'],
  ['NBO.FoodOverfGourmandMult_Tip', 'NBO.Need_Food.GourmandMult_Tip'],
  ['NBO.FoodOverfShowHediffLvl', 'NBO.Need_Food.ShowHediffLvl'],
  ['NBO.FoodOverfShowHediffLvl_Tip', 'NBO.Need_Food.ShowHediffLvl_Tip'],
  ['NBO.FoodOverfLevel', 'NBO.Need_Food.HealthStat.Level'],
  ['NBO.FoodHungerFactor', 'NBO.Need_Food.HealthStat.HungerFactor'],
  ['NBO.FoodHealingFactor', 'NBO.Need_Food.HealthStat.HealingFactor'],
  ['NBO.FoodMovingOffset', 'NBO.Need_Food.HealthStat.MovingOffset'],
  ['NBO.FoodVomitFreq', 'NBO.Need_Food.HealthStat.VomitFreq'],
  ['NBO.FoodEatingOffset', 'NBO.Need_Food.HealthStat.EatingOffset'],
  ['NBO.RestOverfEnabled', 'NBO.Need_Rest.OverfEnabled'],
  ['NBO.RestOverfEnabled_Tip', 'NBO.Need_Rest.OverfEnabled_Tip'],
  ['NBO.RestOverfPerc', 'NBO.Need_Rest.OverfPerc'],
  ['NBO.RestOverfPerc_Tip', 'NBO.Need_Rest.OverfPerc_Tip'],
  ['NBO.RestOverfFastDrain', 'NBO.Need_Rest.FastDrain'],
  ['NBO.RestOverfFastDrain_Tip', 'NBO.Need_Rest.FastDrain_Tip'],
  ['NBO.RestOverfSlowGain', 'NBO.Need_Rest.SlowGain'],
  ['NBO.RestOverfSlowGain_Tip', 'NBO.Need_Rest.SlowGain_Tip'],
  ['NBO.JoyOverfEnabled', 'NBO.Need_Joy.OverfEnabled'],
  ['NBO.JoyOverfEnabled_Tip', 'NBO.Need_Joy.OverfEnabled_Tip'],
  ['NBO.JoyOverfPerc', 'NBO.Need_Joy.OverfPerc'],
  ['NBO.JoyOverfPerc_Tip', 'NBO.Need_Joy.OverfPerc_Tip'],
  ['NBO.JoyOverfFastDrain', 'NBO.Need_Joy.FastDrain'],
  ['NBO.JoyOverfFastDrain_Tip', 'NBO.Need_Joy.FastDrain_Tip'],
  ['NBO.JoyOverfSlowGain', 'NBO.Need_Joy.SlowGain'],
  ['NBO.JoyOverfSlowGain_Tip', 'NBO.Need_Joy.SlowGain_Tip'],
  ['NBO.MoodOverfEnabled', 'NBO.Need_Mood.OverfEnabled'],
  ['NBO.MoodOverfEnabled_Tip', 'NBO.Need_Mood.OverfEnabled_Tip'],
  ['NBO.MoodOverfPerc', 'NBO.Need_Mood.OverfPerc'],
  ['NBO.MoodOverfPerc_Tip', 'NBO.Need_Mood.OverfPerc_Tip'],
  ['NBO.BeautyOverfEnabled', 'NBO.Need_Beauty.OverfEnabled'],
  ['NBO.BeautyOverfEnabled_Tip', 'NBO.Need_Beauty.OverfEnabled_Tip'],
  ['NBO.BeautyOverfPerc', 'NBO.Need_Beauty.OverfPerc'],
  ['NBO.BeautyOverfPerc_Tip', 'NBO.Need_Beauty.OverfPerc_Tip'],
  ['NBO.ComfortOverfEnabled', 'NBO.Need_Comfort.OverfEnabled'],
  ['NBO.ComfortOverfEnabled_Tip', 'NBO.Need_Comfort.OverfEnabled_Tip'],
  ['NBO.ComfortOverfPerc', 'NBO.Need_Comfort.OverfPerc'],
  ['NBO.ComfortOverfPerc_Tip', 'NBO.Need_Comfort.OverfPerc_Tip'],
  ['NBO.ChemicalOverfEnabled', 'NBO.Need_Chemical.OverfEnabled'],
  ['NBO.ChemicalOverfEnabled_Tip', 'NBO.Need_Chemical.OverfEnabled_Tip'],
  ['NBO.ChemicalOverfPerc', 'NBO.Need_Chemical.OverfPerc'],
  ['NBO.ChemicalOverfPerc_Tip', 'NBO.Need_Chemical.OverfPerc_Tip'],
  ['NBO.ChemicalAnyOverfEnabled', 'NBO.Need_Chemical_Any.OverfEnabled'],
  ['NBO.ChemicalAnyOverfEnabled_Tip', 'NBO.Need_Chemical_Any.OverfEnabled_Tip'],
  ['NBO.ChemicalAnyOverfPerc', 'NBO.Need_Chemical_Any.OverfPerc'],
  ['NBO.ChemicalAnyOverfPerc_Tip', 'NBO.Need_Chemical_Any.OverfPerc_Tip'],
  ['NBO.OutdoorsOverfEnabled', 'NBO.Need_Outdoors.OverfEnabled'],
  ['NBO.OutdoorsOverfEnabled_Tip', 'NBO.Need_Outdoors.OverfEnabled_Tip'],
  ['NBO.OutdoorsOverfPerc', 'NBO.Need_Outdoors.OverfPerc'],
  ['NBO.OutdoorsOverfPerc_Tip', 'NBO.Need_Outdoors.OverfPerc_Tip'],
  ['NBO.IndoorsOverfEnabled', 'NBO.Need_Indoors.OverfEnabled'],
  ['NBO.IndoorsOverfEnabled_Tip', 'NBO.Need_Indoors.OverfEnabled_Tip'],
  ['NBO.IndoorsOverfPerc', 'NBO.Need_Indoors.OverfPerc'],
  ['NBO.IndoorsOverfPerc_Tip', 'NBO.Need_Indoors.OverfPerc_Tip'],
  ['NBO.SuppressionOverfEnabled', 'NBO.Need_Suppression.OverfEnabled'],
  ['NBO.SuppressionOverfEnabled_Tip', 'NBO.Need_Suppression.OverfEnabled_Tip'],
  ['NBO.SuppressionOverfPerc', 'NBO.Need_Suppression.OverfPerc'],
  ['NBO.SuppressionOverfPerc_Tip', 'NBO.Need_Suppression.OverfPerc_Tip'],
  ['NBO.RoomSizeOverfEnabled', 'NBO.Need_RoomSize.OverfEnabled'],
  ['NBO.RoomSizeOverfEnabled_Tip', 'NBO.Need_RoomSize.OverfEnabled_Tip'],
  ['NBO.RoomSizeOverfPerc', 'NBO.Need_RoomSize.OverfPerc'],
  ['NBO.RoomSizeOverfPerc_Tip', 'NBO.Need_RoomSize.OverfPerc_Tip'],
  ['NBO.DeathrestOverfEnabled', 'NBO.Need_Deathrest.OverfEnabled'],
  ['NBO.DeathrestOverfEnabled_Tip', 'NBO.Need_Deathrest.OverfEnabled_Tip'],
  ['NBO.DeathrestOverfPerc', 'NBO.Need_Deathrest.OverfPerc'],
  ['NBO.DeathrestOverfPerc_Tip', 'NBO.Need_Deathrest.OverfPerc_Tip'],
  ['NBO.KillThirstOverfEnabled', 'NBO.Need_KillThirst.OverfEnabled'],
  ['NBO.KillThirstOverfEnabled_Tip', 'NBO.Need_KillThirst.OverfEnabled_Tip'],
  ['NBO.KillThirstOverfPerc', 'NBO.Need_KillThirst.OverfPerc'],
  ['NBO.KillThirstOverfPerc_Tip', 'NBO.Need_KillThirst.OverfPerc_Tip'],
  ['NBO.KillThirstOverfFastDrain', 'NBO.Need_KillThirst.FastDrain'],
  ['NBO.KillThirstOverfFastDrain_Tip', 'NBO.Need_KillThirst.FastDrain_Tip'],
  ['NBO.KillThirstOverfSlowGain', 'NBO.Need_KillThirst.SlowGain'],
  ['NBO.KillThirstOverfSlowGain_Tip', 'NBO.Need_KillThirst.SlowGain_Tip'],
  ['NBO.MechEnergyOverfEnabled', 'NBO.Need_MechEnergy.OverfEnabled'],
  ['NBO.MechEnergyOverfEnabled_Tip', 'NBO.Need_MechEnergy.OverfEnabled_Tip'],
  ['NBO.MechEnergyOverfPerc', 'NBO.Need_MechEnergy.OverfPerc'],
  ['NBO.MechEnergyOverfPerc_Tip', 'NBO.Need_MechEnergy.OverfPerc_Tip'],
  ['NBO.LearningOverfEnabled', 'NBO.Need_Learning.OverfEnabled'],
  ['NBO.LearningOverfEnabled_Tip', 'NBO.Need_Learning.OverfEnabled_Tip'],
  ['NBO.LearningOverfPerc', 'NBO.Need_Learning.OverfPerc'],
  ['NBO.LearningOverfPerc_Tip', 'NBO.Need_Learning.OverfPerc_Tip'],
  ['NBO.PlayOverfEnabled', 'NBO.Need_Play.OverfEnabled'],
  ['NBO.PlayOverfEnabled_Tip', 'NBO.Need_Play.OverfEnabled_Tip'],
  ['NBO.PlayOverfPerc', 'NBO.Need_Play.OverfPerc'],
  ['NBO.PlayOverfPerc_Tip', 'NBO.Need_Play.OverfPerc_Tip'],
  ['NBO.DefaultOverfEnabled', 'NBO.Need.OverfEnabled'],
  ['NBO.DefaultOverfEnabled_Tip', 'NBO.Need.OverfEnabled_Tip'],
  ['NBO.DefaultOverfPerc', 'NBO.Need.OverfPerc'],
  ['NBO.DefaultOverfPerc_Tip', 'NBO.Need.OverfPerc_Tip'],
  ['NBO.AuthorityOverfEnabled', 'NBO.Need_Authority.OverfEnabled'],
  ['NBO.AuthorityOverfEnabled_Tip', 'NBO.Need_Authority.OverfEnabled_Tip'],
  ['NBO.AuthorityOverfPerc', 'NBO.Need_Authority.OverfPerc'],
  ['NBO.AuthorityOverfPerc_Tip', 'NBO.Need_Authority.OverfPerc_Tip'],
  ['NBO.SadismOverfEnabled', 'NBO.Need_Sadism.OverfEnabled'],
  ['NBO.SadismOverfEnabled_Tip', 'NBO.Need_Sadism.OverfEnabled_Tip'],
  ['NBO.SadismOverfPerc', 'NBO.Need_Sadism.OverfPerc'],
  ['NBO.SadismOverfPerc_Tip', 'NBO.Need_Sadism.OverfPerc_Tip']
]

replacement_keys = sorted(replacement_keys, key=lambda x: len(x[0]), reverse=True)

import os

def list_files(dir_path):
  files = []
  for file_name in os.listdir(dir_path):
    file_path = os.path.join(dir_path, file_name)
    if os.path.isfile(file_path) and file_name == "NeedBarOverflow.xml":
      files.append(file_path)
    elif os.path.isdir(file_path):
      files.extend(list_files(file_path))
  return files

def replace_xml_file(file_path):
  with open(file_path, encoding= "utf-8") as f:
    read_text = f.read()
  replacement_text = read_text
  for key_pairs in replacement_keys:
    replacement_text = replacement_text.replace(key_pairs[0], key_pairs[1])
  if read_text == replacement_text:
    print(f"No change to file (未修改以下文件): {file_path}")
    return
  with open(file_path, "w", encoding= "utf-8") as f:
    f.write(replacement_text)
  print(f"Overwriting file (覆盖了以下文件): {file_path}")

if __name__ == "__main__":
  all_files = list_files(os.getcwd())
  for file_path in all_files:
    replace_xml_file(file_path)
  s = input("Done, press ENTER to exit. 完成，按回车键退出……")
  print(s)
